package repository

import (
	"SeatSystem/internal/model"
	"errors"
	"fmt"
)

func Login(phone, pwd string) (user model.User, err error) {
	db.Where("phone = ?", phone).First(&user)
	fmt.Println(user)
	fmt.Println("pwd:", pwd)
	fmt.Println("phone:", phone)
	if user.Pwd != pwd {
		return user, errors.New("密码错误")
	}
	return user, verify(user.ID)
}

func GetClassList() (classList []model.Class, err error) {
	db.Find(&classList)
	return classList, verify(len(classList))
}

func GetSeatList(cid int) (seatList []model.Seat, err error) {
	db.Where("cid = ?", cid).Find(&seatList)
	return seatList, verify(len(seatList))
}

func GetHistoryList(uid int) (histroyList []model.History, err error) {
	db.Where("uid = ?", uid).Find(&histroyList)
	return histroyList, verify(len(histroyList))
}

func GetTimeList(sid int) (timeList []model.Time, err error) {
	db.Where("sid = ?", sid).Find(&timeList)
	return timeList, verify(len(timeList))
}

func GetFeedBackList() (list []model.FeedBack) {
	db.Find(&list)
	return list
}

func GetHistory(id int) {

}

func GetTime(id int) {

}
